<!-- 页面导航栏 -->
<template>
	<view :style="{height: height+'px'}">
		<view id="navigate" :class="['navigate-wrap', isSticky? 'sticky':'']"
			:style="[{backgroundColor:backgroundColor}]">
			<!-- 手机状态栏占位 -->
			<cc-statusbar-placeholder />
			<view class="navigate-bar">
				<!-- 返回及分享按钮 -->
				<view class="nav-left">
					<view class="button-wrap">
						<uni-icons v-if="buttons.includes('back')" type="left" @click="back" size="24" />
					</view>
				</view>
				<!-- 标题 -->
				<view class="nav-title">{{title}}</view>
				<!-- 小程序胶囊按钮 -->
				<view class="nav-right"></view>
			</view>
			<slot></slot>
		</view>
	</view>
</template>

<script>
	export default {
		name: "cc-navigate",
		emits: [],
		props: {
			// 标题居中
			title: {
				type: String,
				default: ''
			},
			// 按钮数组
			buttons: {
				type: Array,
				default: () => [],
			},
			// 是否吸顶
			isSticky: {
				type: Boolean,
				default: true,
			},
			// 背景色
			backgroundColor: {
				type: String,
				default: "#f8f8f8",
			}
		},
		data() {
			return {
				height: 0,
			};
		},
		created() {},
		mounted() {
			const query = uni.createSelectorQuery().in(this);
			query.select('#navigate').boundingClientRect(res => {
				this.height = res.height;
			}).exec();
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navigate-wrap {
		z-index: 10001;

		&.sticky {
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			animation: fadeIn 0.3s forwards;
			font-size: 38rpx;
			text-overflow: ellipsis;
			//box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.15); 
		}
	}

	.navigate-bar {
		height: 88rpx;
		width: 100vw;
		display: flex;
		padding: 0;
		justify-content: space-between;
		align-items: center;

		.nav-left {
			width: 220rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;

			.button-wrap {
				display: flex;
				align-items: center;
				height: 60rpx;
				border-radius: 22rpx;
				//border: 1rpx solid #c8c7cc;
				padding: 0 15rpx;
				gap: 15rpx;
			}

			.divider {
				width: 1rpx;
				height: 35rpx;
				background-color: #c8c7cc;
				opacity: 0.9;
			}
		}

		.nav-title {
			flex: 1;
			font-size: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.nav-right {
			width: 220rpx;
			justify-content: flex-end;
		}
	}
</style>